package com.syqc.videos.real

import android.view.View
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.base.BaseRealFragment
import com.syqc.entity.VideoAlarm
import com.syqc.monitor.R
import com.syqc.monitor.databinding.FragVideoAlarmBinding

/**
 *@author  hfjs
 *@time   2024/12/31 9:45
 *@desc
 */
class VideoAlarmFragment(private val type: Int) : BaseRealFragment<FragVideoAlarmBinding>(type,FragVideoAlarmBinding::inflate) {
    private val mAdapter by lazy { AlarmAdapter() }
    private val mVM by viewModels<VideoAlarmVM>()
    override fun hide() {
        mVM.stopTime()
    }

    override fun initView(view: View) {
        binding.rvVideoAlarm.layoutManager = LinearLayoutManager(requireContext())
        binding.rvVideoAlarm.adapter = mAdapter
    }

    override fun initData() {
        mVM.alarmLive.observe(this) {
            mAdapter.setList(it)
        }
    }

    override fun initEvent() {

    }

    fun setCarId(carId: String) {
        mVM.carId = carId
    }


}

class AlarmAdapter :
    BaseQuickAdapter<VideoAlarm, BaseViewHolder>(R.layout.item_video_alarm) {
    private val normal_: String by lazy { context.getString(R.string.desc_video_alarm_normal_) }
    private val normal: String by lazy { context.getString(R.string.desc_video_alarm_normal) }

    override fun convert(holder: BaseViewHolder, item: VideoAlarm) {
        holder.setText(R.id.tvAlarmName, item.alarmTitleId)
        holder.setImageResource(R.id.ivAlarmPic, item.alarmImgId)
        if (item.isNormal) {
            holder.setBackgroundResource(R.id.tvAlarmType, R.drawable.bg_alarm_normal_)
            holder.setText(R.id.tvAlarmType, normal_)
        } else {
            holder.setBackgroundResource(R.id.tvAlarmType, R.drawable.bg_alarm_normal)
            holder.setText(R.id.tvAlarmType, normal)
        }
    }
}